home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
powervww
/
pvitems.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-05
|
36KB
|
1,618 lines
// ____________________________________________________
// | |
// | Project: POWER VIEW INTERFACE |
// | File: PVITEMS.CPP |
// | Compiler: WPP386 (10.6) |
// | |
// | Subject: Base class for PV items |
// | |
// | Author: Emil Dotchevski |
// |____________________________________________________|
//
// E-mail: zajo@geocities.com
// URL: http://www.geocities.com/SiliconValley/Bay/3577
#define uses_app
#define uses_colors
#define uses_dc
#define uses_desk
#define uses_help
#define uses_system
#define DECLARE_PVITEMS
#include "PVuses.h"
#undef DECLARE_PVITEMS
#ifndef NOHELP
static uint help_context = 0;
#endif
static void *command_information = NULL;
static uint command_size = 0;
boolean is_valid( Titem *item )
{
if( ( item != NULL ) && item->valid( cmVALID ) ) return 1;
DELETE( item );
return 0;
}
#ifndef NOHELP
void _help( uint hlp_ctx )
{
if( !help_context ) help_context = hlp_ctx;
}
uint __help( void )
{
uint h;
h = help_context;
help_context = 0;
return h;
}
#endif
void _command_info( void *cmd_info, uint cmd_size )
{
command_information = cmd_info;
command_size = cmd_size;
}
Titem *message( Titem *receiver, uint command )
{
if( receiver != NULL )
return receiver->handle_command( receiver, command );
else
return NULL;
}
Titem *broadcast( uint command )
{
return application->handle_command( NULL, command );
}
Titem *modal_broadcast( uint command )
{
if( modal_item != NULL )
return modal_item->handle_command( NULL, command );
else
return NULL;
}
//Titem publics:
/*
Description:
Construct item with given bounds.
Entry:
_xl, _yl: item width,heigh.
*/
Titem::Titem( int _xl, int _yl )
{
flags_word = ifVISIBLE+ifSELECTABLE+ifCLOSEABLE+ifMOVABLE+ifRESIZEABLE+ifTAB_STOP;
state_word = 0;
event_mask = evCOMMAND+evKEYBOARD;
#ifndef NOMOUSE
event_mask |= evMOUSE_DOWN+evMOUSE_UP+evMOUSE_DRAG;
#endif
next = NULL;
owner = NULL;
last = NULL;
current = NULL;
bound_x = x = 0;
bound_y = y = 0;
bound_xl = xl = _xl;
bound_yl = yl = _yl;
curs_x = 0;
curs_y = 0;
curs_type = 0;
grow_mode = gmDONT_GROW;
drag_mode = dmDONT_DRAG;
#ifndef NOHELP
help_ctx = __help();
#endif
drop_id = 0;
stop_state = 0;
backgrnd_attr = 0;
backgrnd_char = ' ';
items_changed = 0;
set_state( isVALID+isACTIVE, 1 );
}
/*
Description:
Dispose all subitems. Exclude self from the owner's list.
*/
Titem::~Titem( void )
{
while( last != NULL )
if( last->flags( ifSTAY ) )
remove( last );
else
DELETE( last );
if( owner != NULL ) owner->remove( this );
cancel_update( this );
}
/*
Description:
Returns pointer to the first (topmost) sub-item, or NULL.
*/
Titem *Titem::first( void )
{
if( last != NULL )
return last->next;
else
return NULL;
}
/*
Description:
Returns pointer to the previous sub-item in the owner's list (circular),
or NULL if item has no owner;
*/
Titem * Titem::prev( void )
{
Titem *p;
if( owner == NULL )
return NULL;
else
{
p = this;
while( p->next != this)
{
p = p->next;
}
return p;
}
}
/*
Description:
Returns pointer to the next sub-item in the owner's list (linear),
or NULL if it is the last item, or has no owner;
*/
Titem * Titem::nextl( void )
{
if( ( owner == NULL ) || ( owner->last == this ) )
return NULL;
else
return next;
}
/*
Description:
Returns pointer to the previous sub-item in the owner's list (linear),
or NULL if it is the first item, or has no owner;
*/
Titem * Titem::prevl( void )
{
if( ( owner == NULL ) || ( owner->first() == this ) )
return NULL;
else
return prev();
}
/*
Description:
Set or clear flags_word bits depending on 'enable'. Handle some special
cases. Can be overriden to handle more special cases.
Entry:
_flags_word: requested bit mask;
enable: 1 - set bits, 0 - clear.
*/
void Titem::set_flags( uint _flags_word, boolean enable )
{
uint f;
if( ( _flags_word & ifSELECTABLE ) && !enable && state( isSELECTED ) )
{
set_state( isSELECTED, 0 );
if( state( isSELECTED ) ) _flags_word &= ~ifSELECTABLE;
}
f = flags_word;
if( enable )
flags_word |= _flags_word;
else
flags_word &= ~_flags_word;
if( ( f != flags_word ) && ( _flags_word & ifVISIBLE ) ) redraw();
}
/*
Description:
Set or clear state bits depending on 'enable'. Handle some special
cases. Can be overriden to handle more special cases.
Entry:
_state_word: requested bit mask;
enable: 1 - set bits, 0 - clear.
*/
void Titem::set_state( uint _state_word, boolean enable )
{
uint s, ns;
boolean f;
Titem *p;
if( enable )
{
if( ( _state_word & isACTIVE ) &&
flags( ifSELECTABLE ) && !state( isSELECTED ) )
_state_word &= ~isACTIVE;
if( ( _state_word & isACCESSABLE ) && !event_mask )
_state_word &= ~isACCESSABLE;
if( ( _state_word & isALIVE ) && ( !flags( ifVISIBLE ) || state( isHIDDEN ) ) )
_state_word &= ~isALIVE;
if( ( _state_word & isSELECTED ) &&
( !flags(ifSELECTABLE) || owner==NULL ||
( ( ( p = owner->current ) != NULL ) &&
( p->set_state( isSELECTED, 0 ),
p->state( isSELECTED )
)
)
)
)
_state_word &= ~isSELECTED;
}
else
if( ( _state_word & isSELECTED ) && state( isFOCUSED ) && !release_focus() )
_state_word &= ~isSELECTED;
if( enable ) ns = state_word | _state_word; else ns = state_word & ~_state_word;
if( state_word == ns ) return;
s = _state_word & ( isACTIVE+isALIVE+isDISABLED+isACCESSABLE );
if( s )
for( p=first(); p!=NULL; p=p->nextl() )
p->set_state( s, enable );
f = ( ( _state_word & ( isFOCUSED+isSELECTED+isDISABLED+isHIDDEN ) ) != 0 );
if( f ) redraw();
s = state_word; state_word = ns;
if( ( state_word & isHIDDEN ) != ( s & isHIDDEN ) )
{
set_state( isALIVE, !enable && owner && owner->state( isALIVE ) );
if( owner != NULL )
if( enable )
req_update( owner );
else
owner->update_bounds( this );
}
if( ( state_word & isDISABLED ) != ( s & isDISABLED ) )
set_state( isACTIVE, !enable );
if( ( state_word & isSELECTED ) != ( s & isSELECTED ) )
{
set_state( isACTIVE, enable );
if( owner != NULL )
if( enable )
{
owner->current = this;
p = owner;
while( ( p != modal_item ) && ( p->owner != NULL ) && ( p->owner->current == p ) )
p = p->owner;
if( p == modal_item ) set_state( isFOCUSED, 1 );
}
else
{
owner->current = NULL;
set_state( isFOCUSED, 0 );
}
}
if( ( state_word & isFOCUSED ) != ( s & isFOCUSED ) )
{
if( enable ) get_focused();
if( current != NULL ) current->set_state( isFOCUSED, enable );
}
if( f ) redraw();
if( ( state_word & isMODAL ) != ( s & isMODAL ) )
{
set_state( isACCESSABLE, enable );
if( enable ) set_state( isACTIVE, 1 );
}
if( ( _state_word & isON_TOP ) && owner )
if( enable )
owner->pop_item( this );
else
owner->do_pop_top_items( owner->last );
}
/*
Description:
Test state of the item's owner just before desktop or application.
Usually used to determine is the window that (indirectly) owns the
item active, selected, and so on.
*/
boolean Titem::window_state( uint _state_word )
{
Titem *p;
p = this;
while( p->owner != NULL )
{
if( ( p->owner == desktop ) || ( p->owner == application ) )
return p->state( _state_word );
p = p->ow